<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Access {
	protected $CI;
	protected $user_model;
	
	function __construct() {
		$this->CI =& get_instance();
		$this->CI->load->model('user_model');
		$this->user_model =& $this->CI->user_model;
	}
	
	function login($nim,$pwd){
		$login_result = $this->user_model->check_login($nim,$pwd);
		if($login_result){
			$user_data = array(
				'nim'=>$login_result['nim'],
				'nama'=>$login_result['nama'],
				'nilai_pti_b'=>$login_result['nilai_pti_b'],
				'nilai_pti_c'=>$login_result['nilai_pti_c'],
				'role'=>$login_result['role']
			);
			$this->CI->session->set_userdata($user_data);
			return TRUE;
		}else{
			return FALSE;
		}
	}
	
	function is_login(){
		return ($this->CI->session->userdata('nim')
				&& $this->CI->session->userdata('nama')
				&& $this->CI->session->userdata('role'));
	}
	
	function logout(){
		$this->CI->session->unset_userdata('nim');
		$this->CI->session->unset_userdata('nama');
		$this->CI->session->unset_userdata('nilai_tes');
		$this->CI->session->unset_userdata('role');
	}
}
/** End of file */